package ist.swt.snippet.text;


import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;

public class Snippet_Text {

	/**
	 * @param args
	 */
	Display display = null;
	Shell shell = null;	
	
	
	
	
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		(new Snippet_Text()).execute();
	}	
	public Snippet_Text() {
		// TODO Auto-generated constructor stub
		super();
		initialize();
	}	
	private void initialize()
	{
		display = new Display();		
		shell = new Shell(display, 
				//SWT.RESIZE | 
				SWT.MIN);
		shell.setSize(500, 600);
		shell.setText("IST Java");


		initialize_Shell();
		
		
	}		
	
	
	public void execute()
	{
		shell.open();	
		while (!shell.isDisposed()) 
		{
			if(!display.readAndDispatch())
				display.sleep();			
		}
		display.dispose();
	}
	
	
	private void initialize_Shell()
	{
		/**
		 * Una sóla line
		 */
		final Text text_field = new Text(shell, 
				SWT.SINGLE | 
				// SWT.PASSWORD | // Asteriscos
				SWT.BORDER);
		
		/**
		 * Texto por defecto
		 */
		text_field.setText("Salut i mundi");
		
		/**
		 * Máximo número de caracteres
		 */
		// text_field.setTextLimit(3);
		
		/**
		 * text_field.setBounds(X, Y, Ancho, Alto);
		 */
		text_field.setBounds(10, 10, 180, 20);
		

		
		/**
		 * Multilinea
		 */
		final Text text_area = new Text(shell,
				SWT.MULTI |
				SWT.BORDER |
				SWT.V_SCROLL |
				SWT.H_SCROLL |
				SWT.WRAP); // Autoajustar texto
		text_area.setBounds(10,40,250,250);
		
		
		
		
		/**
		 * Boton Añadir
		 */
		Button button_Add = new Button(shell, SWT.PUSH);
		button_Add.setText("Añadir");
		button_Add.setBounds(310, 10, 180, 30);

		button_Add.addSelectionListener(new SelectionAdapter() {
			
			@Override
			public void widgetSelected(SelectionEvent e) {
				System.out.println("Boton añadir");
				/**
				 * Método "append" para añadir texto
				 */
				text_area.append(text_field.getText());
			}
			
		});
		
		
		
		
		
		
		
		/**
		 * Botón insertar
		 */
		Button button_Insert = new Button(shell, SWT.PUSH);
		button_Insert.setText("Insertar");
		button_Insert.setBounds(310, 50, 180, 30);
	
		button_Insert.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				System.out.println("Boton insertar");
				/**
				 * Método sestText para reemplazar texto
				 */
				text_area.setText(text_field.getText());
			}
		});
		
		
		
		
		/**
		 * Botón de Check
		 */
		Button button_Check = new Button(shell, SWT.CHECK);
		button_Check.setText("Boton Check");
		button_Check.setBounds(310, 80, 180, 30);
		button_Check.setSelection(false);
		
		
		
		/**
		 * Botones de Radio
		 */
		Button button_RadioA = new Button(shell, SWT.RADIO);
		button_RadioA.setText("Opción A");
		button_RadioA.setBounds(310, 120, 100, 30);
		button_RadioA.setSelection(true);
		
		Button button_RadioB = new Button(shell, SWT.RADIO);
		button_RadioB.setText("Opción B");
		button_RadioB.setBounds(430, 120, 100, 30);
		button_RadioB.setSelection(false);
		
		
		
		
		
		
		
		
		
		
		
	}
	
	

}
